/*
 * Copyright @ 苏州瑞云信息技术有限公司 All rights reserved.
 */
package cn.com.recloud.bbs.controller;


import cn.com.recloud.bbs.dto.CampaignAnalysisDTO;
import cn.com.recloud.core.util.Result;
import cn.com.recloud.one.spring.exception.OneException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import cn.com.recloud.one.spring.controller.BaseController;

import cn.com.recloud.bbs.entity.bbs_campaign_sign_up;
import cn.com.recloud.bbs.service.CampaignSignUpService;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author kim dong
 * @date 2020-04-28
 */
@RestController
@RequestMapping("/api/bbs/camppaignsignup")
@Api(tags = "活动报名相关接口")
public class CampaignSignUpController extends BaseController<bbs_campaign_sign_up,CampaignSignUpService> {
    @Autowired
    private CampaignSignUpService signUpService;
    @PostMapping("/serchcampaignsignup")
    @ApiOperation("查询活动报名情况")
    public Result serchCampaignSignUp(@RequestBody CampaignAnalysisDTO dto){
        Map map=signUpService.serchCampaignSignUp(dto);
        return new Result(map);
    }
    @PostMapping("exportcampaignupanalysis")
    @ApiOperation("导出活动报名的统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "response", value = "响应对象"),
            @ApiImplicitParam(name = "campaign", value = "活动查询的dto")
    })
    public void exportCampaignUpAnalysis(HttpServletResponse response, @RequestBody CampaignAnalysisDTO campaign) {
        signUpService.exportCampaignUpAnalysis(campaign, response);
    }

    @PostMapping("signupcampaign")
    @ApiOperation("活动报名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bbsCampaignSignUp", value = "活动报名的对象")
    })
    public Result signUpCampaign(@RequestBody bbs_campaign_sign_up bbsCampaignSignUp){
        if(StringUtils.isBlank(bbsCampaignSignUp.getBbs_campaignid())){
            throw new OneException("活动id不能为空");
        }
        if(StringUtils.isBlank(bbsCampaignSignUp.getName())){
            throw new OneException("活动名称不能为空");
        }
        signUpService.signUpCampaign(bbsCampaignSignUp);
        return Result.SUCCESS;
    }
}

